#include "stopinfo.h"
#include "ui_stopinfo.h"

stopinfo::stopinfo(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::stopinfo)
{
    ui->setupUi(this);
}

stopinfo::~stopinfo()
{
    delete ui;
}
void stopinfo::paint(){

    image = QImage(800,800,QImage::Format_RGB32);  //画布的初始化大小设为600*500，使用32位颜色
    QColor backColor = qRgb(255,255,255);    //画布初始化背景色使用白色
    image.fill(backColor);//对画布进行填充
    QPainter painter(&image);

    painter.setRenderHint(QPainter::Antialiasing, true);
    int pointx=80,pointy=420;//确定坐标轴起点坐标，这里定义(80,420)
    int width=600,height=300;//确定坐标轴宽度跟高度 上文定义画布为600X300，宽高依此而定。
    //绘制坐标轴 坐标轴原点(35，280)
    painter.drawRect(30,100,690,350);//外围的矩形，从(5,5)起，到(590,290)结束，周围留了5的间隙。
    painter.drawLine(pointx,pointy,width+pointx,pointy);//坐标轴x宽度为width
    painter.drawLine(pointx,pointy-height,pointx,pointy);//坐标轴y高度为height
    int i;
    int n=10;
    for(int i=0;i<10;i++)//分成10份
    {
        painter.drawText(pointx+(i+0.65)*width/10,pointy+10,QString::number((int)((i)*((double)n/10))));
    }
    double _maStep=1;
    for(int i=0;i<10;i++)
       {
           //主要就是确定一个位置，然后画一条短短的直线表示刻度。
           painter.drawText(pointx-20,pointy-(i+0.85)*height/10,
                            QString::number((int)(_maStep*(i))));
       }
    QPen pen;
    QPointF pointf[10];
    pen.setWidth(6);
    painter.setBrush(QBrush(Qt::green));
    painter.drawEllipse(112,380,20,20);
    painter.drawEllipse(592,110,20,20);
    painter.setBrush(QBrush(Qt::blue));
    painter.drawEllipse(112,110,20,20);
    painter.drawEllipse(592,380,20,20);
    painter.drawPoints(pointf, 10);
    //pen.setColor(Qt::red); // 设置画笔为黄色
    //painter.setPen(pen); // 设置画笔
    int raw;
    int col;
    for(raw=0;raw<5;raw++){
        for(col=1;col<9;col++){
            this->query.exec(QString("select * from place where x='%1' and y='%2'").arg(raw*2).arg(col));
            this->query.next();
            int status=this->query.value(3).toInt();
            if(status==0){
                painter.setBrush(QBrush(Qt::white));
                QRectF rectangle2(112+120*raw,380-30*col,20,20);
                painter.drawRect(rectangle2);
            }
            if(status==1){
                painter.setBrush(QBrush(Qt::red));
                QRectF rectangle2(112+120*raw,380-30*col,20,20);
                painter.drawRect(rectangle2);
            }
            if(status==2){
                painter.setBrush(QBrush(Qt::black));
                QRectF rectangle2(112+120*raw,380-30*col,20,20);
                painter.drawRect(rectangle2);
            }

        }
    }
    painter.setBrush(QBrush(Qt::green));
    painter.drawEllipse(650,150,20,20);
    pen.setColor(Qt::black);
    painter.drawText(670,165,"：入口");
    painter.setBrush(QBrush(Qt::blue));
    painter.drawEllipse(650,175,20,20);
    pen.setColor(Qt::black);
    painter.drawText(670,190,"：出口");
    painter.setBrush(QBrush(Qt::white));
    QRectF rectangle2(650,200,20,20);
    painter.drawRect(rectangle2);
    pen.setColor(Qt::black);
    painter.drawText(670,215,"：空车");
    painter.setBrush(QBrush(Qt::red));
    QRectF rectangle3(650,225,20,20);
    painter.drawRect(rectangle3);
    pen.setColor(Qt::black);
    painter.drawText(670,240,"：有车");
    painter.setBrush(QBrush(Qt::black));
    QRectF rectangle4(650,255,20,20);
    painter.drawRect(rectangle4);
    pen.setColor(Qt::black);
    painter.drawText(670,270,"：已定");
    //QRectF rectangle2(112.0, 200.0,20.0, 20.0);
    //painter.drawRect(rectangle2);
}

void stopinfo::on_pushButton_clicked()
{
    this->close();
}
